import Sequelize from 'sequelize';
import baseDao from '../lib/baseDao.js'; // 数据库操作

const Modal = baseDao.sequelize.define('t_favorite', {
  // 属性
  id: {
    type: Sequelize.INTEGER,
    primaryKey: true, // 主键
    autoIncrement: true, // 自增
    allowNull: true,
    validate: {
      len: [1, 50]
    }
  },
  userId: {
    type: Sequelize.INTEGER,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '收藏者ID'
  },
  goodsId: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '淘宝商品ID'
  },
  dtitle: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 100]
    },
    comment: '商品短标题'
  },
  mainPic: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 200]
    },
    comment: '商品主图'
  },
  brandName: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '品牌名称'
  },
  tId: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '大淘客商品ID'
  },
  couponPrice: {
    type: Sequelize.FLOAT(10, 2),
    allowNull: true,
    validate: {
      len: [0, 10]
    },
    comment: '优惠券面额'
  },
  couponEndTime: {
    type: Sequelize.STRING,
    allowNull: true,
    validate: {
      len: [0, 50]
    },
    comment: '优惠券过期时间'
  },
  actualPrice: {
    type: Sequelize.FLOAT(10, 2),
    allowNull: true,
    validate: {
      len: [0, 10]
    },
    comment: '券后价'
  },
  originalPrice: {
    type: Sequelize.FLOAT(10, 2),
    allowNull: true,
    validate: {
      len: [0, 10]
    },
    comment: '商品原价'
  },
}, {
    // 参数
    indexes: [{ name: 'id_favorite', unique: true, fields: ['user_id', 'goods_id'] }], // 索引 
  });

//向外暴露
export default {
  Modal,
}